package game.view.panel.game
{
	import com.base.type.LayerEnum;
	import com.greensock.TweenMax;
	import com.net.SocketManage;
	import com.base.event.ZooEvent;
	import flash.events.*;
	import flash.geom.*;
	import flash.text.TextField;
	
	import game.GlobalConfig;
	import game.controller.mediator.GameMediator;
	import game.model.GameData;
	import game.model.type.Enum;
	import game.view.base.gamepanel.GamePanelUI;
	import game.view.panel.other.LabelNoticeView;
	import game.model.type.NoticeCMD;
	import morn.App;
	import morn.core.handlers.Handler;
	import morn.core.managers.ResLoader;
	public class GamePanel extends GamePanelUI
	{
		
		public function GamePanel()
		{
			super();
			setLayerType(LayerEnum.LAYER_PANEL);
			setMediatorClass(GameMediator);
		}
		override protected function initialize():void
		{
			super.initialize();
			trace('GamePanel initialize');
			ZooMain.event.addEventListener(NoticeCMD.NOTICE_Choose,NEXTLEVEL);
			ZooMain.event.addEventListener(NoticeCMD.NOTICE_Detail,DetailFun);
			peopleMc.x=GameData.instance.peoXyList[0].x;peopleMc.y=GameData.instance.peoXyList[0].y;
			peopleMc.visible=false;
			this.setLevel();
		}
		
		override protected function reset():void
		{
			super.reset();
			
		}
		public function loginPanel():void{
			levelGoods.initData();
			this.setLevel();
		}
		/**
		 * 设置关卡 1-6
		 */
		public function setLevel():void{
			peopleMc.visible=false;
			levelGoods.setLevel(GameData.instance.myLevelId);
			uiview.setLevel();
		}
		/**关卡设置完成**/
		public function levelComplete():void{
			peopleMc.visible=GameData.instance.isLogin;
			peopleMc.y=GameData.instance.peoXyList[0].y;
			peopleMc.x=GameData.instance.peoXyList[0].x;
			GameData.instance.isToJump=true;		
			if(GameData.instance.isJxToJ){
				GameData.instance.isJxToJ=false;
				jumBtnClick();
			}else{
				uiview.jumpBtn.visible=true;
			}
		}
		
		
	
		
		public function ExplainBtnClick():void{
			
			if(!GameData.instance.isLogin){
				//LabelNoticeView.instance.showNotice('还未登录.....');
				//return;
			}
			
			var vo:Object={"cmd": "Banner", "params": {'size':0}};
			SocketManage.instance.sendUTF(JSON.stringify(vo));
			
			ZooMain.view.showView(ExplainPanel);	
		}
		
		public function myRecdBtnBtnClick():void{
			//TweenMax.to(peopleMc,0.5,{rotation:359,bezierThrough:getPlopeoXy(2),onComplete:tweenComplete,onCompleteParams:[]});
			if(!GameData.instance.isLogin){
				LabelNoticeView.instance.showNotice('还未登录.....');
				return;
			}
			var vo:Object={"cmd": "Detail", "params": {"pageIndex":1}};
			SocketManage.instance.sendUTF(JSON.stringify(vo));
			
		}
		
		public function DrawResult(data:Object):void{
			trace('GamePanel DrawResult 11');
			this.pelpeoPlay();	
		}
		public function UpdLevelInfo(data:Object):void{
			trace('GamePanel UpdLevelInfo 11');
			uiview.setLevel();
			levelGoods.initData();
		}
		public function FailChoose():void{
			setLevel();
		}
		private function NEXTLEVEL(evt:ZooEvent):void{
			setLevel();
		}
		private function DetailFun(evt:ZooEvent):void{
			//trace('GamePanel DetailFun',evt.data.content.list);
			ZooMain.view.showView(MyRecordPanel,evt.data.content.list);
		}
		private var debugGsLen:int=0;
		private function openResult():void{
			
		}
		public function jumBtnClick():void{
			if(!GameData.instance.isLogin){
				LabelNoticeView.instance.showNotice('还未登录.....');
				return;
			}
			if(!GameData.instance.isToJump){
				LabelNoticeView.instance.showNotice('请稍等.....');
				return;
			}
			if(GameData.instance.isMapMove){
				LabelNoticeView.instance.showNotice('请稍等.....');
				return;
			}
			GameData.instance.isToJump=false;
			uiview.jumpBtn.visible=false;
			if(GameData.instance.lookId!=Enum.no_num){
				GameData.instance.lookId=Enum.no_num;
				uiview.setLevel();
				levelGoods.setLevel(GameData.instance.myLevelId,true);
			}
			
			var vo:Object={"cmd": "Jump", "params": {}};
			SocketManage.instance.sendUTF(JSON.stringify(vo));
			
			
		}
		public function pelpeoPlay():void{
			//TweenMax.to(peopleMc,0.5,{rotation:359,bezierThrough:[{x:197, y:196}, {x:177, y:356}], orientToBezier:true,onComplete:tweenComplete,onCompleteParams:[]});
			if(TweenMax.isTweening(peopleMc))return;
			peopleMc.visible=true;
			var type:int=(GameData.instance.resultData==null?2:1);
			TweenMax.to(peopleMc,0.5,{rotation:359,bezierThrough:getPlopeoXy(type),onComplete:tweenComplete,onCompleteParams:[]});
			
		}
		private function tweenComplete():void{
			trace('GamePanel tweenComplete',TweenMax.isTweening(peopleMc));
			peopleMc.visible=false;
			if(GameData.instance.resultData!=null){
				ZooMain.view.showView(ResultPanel);
			}else{
				ZooMain.view.showView(LostPanel);
			}
		
				
		}	
		/**
		 * type:1跳成功，2失败
		 */
		private function  getPlopeoXy(type:int=1):Array{
			var point:Object=GameData.instance.peoXyList[type];
			var ary:Array=[{x:point.x-100,y:point.y-80},{x:point.x,y:point.y}];
			return ary;
		}
		
	}
}